﻿using Prism.Events;
using System;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Threading.Tasks;

namespace HlELock.Core.Events
{
    public static class EventBus
    {
        public static Lazy<IEventAggregator> aggregator = new Lazy<IEventAggregator>(() => new EventAggregator());
        public static IEventAggregator Instace { get => aggregator.Value; }

        public static void StartDialogLoading(string desc = "")
        {
            Task.Run(() => Instace.GetEvent<DialogWindowBusyEvent>().Publish(new DialogWindowBusyEventArgs { IsBusy = true, Descr = desc }));
        }

        public static void StopDialogLoading()
        {
            Task.Run(() => Instace.GetEvent<DialogWindowBusyEvent>().Publish(new DialogWindowBusyEventArgs { IsBusy = false }));
            RefreshRoomList();
        }
        public static void CloseDialog()
        {
            Task.Run(() => Instace.GetEvent<CloseDialogWindowEvent>().Publish(null));
            RefreshRoomList();
        }
        /// <summary>
        /// 刷新房间列表
        /// </summary>
        public static void RefreshRoomList()
        {
            Task.Run(() => Instace.GetEvent<RefreshRoomListEvent>().Publish());
        }
        public static void RefreshRoomListAction(Action action)
        {
            Instace.GetEvent<RefreshRoomListEvent>().Subscribe(action);
        }
        public static void ShowDialogWindow(DialogWindowEventArgs args)
        {
            Task.Run(() => Instace.GetEvent<DialogWindowEvent>().Publish(args));
        }
        public static void ShowTitle()
        {
            Task.Run(() => Instace.GetEvent<MainWindowEvent>().Publish(new MainWindowEventArgs { TitleIsShow = true }));
        }
        public static void SetUserName(string userName)
        {
            Task.Run(() => Instace.GetEvent<MainWindowEvent>().Publish(new MainWindowEventArgs { UserName = userName }));
        }
        public static void SetDeviceActive()
        {
            Task.Run(() => Instace.GetEvent<MainWindowEvent>().Publish(new MainWindowEventArgs { DeviceActive = true }));
        }

    }
}
